<?php

function GMRequest($data)
{
	$privatekey = file_get_contents('./key.pem');

	$url = 'https://gmasiatech.net/merchant/process.php';

	$res = openssl_pkey_get_private($privatekey);
	$ssl_sign = '';

	if (openssl_sign(md5(json_encode($data)), $ssl_sign, $res)){
		$ssl_sign = base64_encode($ssl_sign);
	}

	$data['ssl_sign'] = $ssl_sign;

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_POST, 1 );
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
	curl_setopt($curl, CURLOPT_SSLKEY, realpath('./key.pem'));
	curl_setopt($curl, CURLOPT_SSLKEYTYPE,'PEM');

	curl_setopt($curl, CURLOPT_POSTFIELDS, $data );
	$response = curl_exec($curl);
	curl_close($curl);

	return $response;
}


$merchantId = 'G2P55121d4dd4251';

$data = array(
	'method'			=>  'reqFundin',
	'merchantId'		=>  $merchantId,
	'depositor'			=>  'zhang_obast',
	'deposit_time'		=>  '2015-03-26',
	'address'			=>  'ShangHai',
	'transaction_type'  =>  'online bank',
	'bank_name'			=>  'ICBC',
	'bank_code'			=>  'ICBC_WMQ_3403',
	'transactionId'		=>  '100000000',
	'amount'			=>  2434
);

$response = GMRequest($data);

print_r($response);
exit;

